package com.hnucm.c201901020121.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.hnucm.c201901020121.Fragment.My.AllPublishTaskFragment;
import com.hnucm.c201901020121.Fragment.My.AuditUnqualifiedFragment;
import com.hnucm.c201901020121.Fragment.My.AuditFinishedFragment;
import com.hnucm.c201901020121.Fragment.My.AuditToBeFragment;
import com.hnucm.c201901020121.R;

public class PublishManageAct extends AppCompatActivity {
    ImageView back;
    ViewPager2 viewPager;
    TabLayout tabLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_publish_manage);
        back=findViewById(R.id.imageView53);
        viewPager=findViewById(R.id.viewPager1);
        tabLayout=findViewById(R.id.tabLayout1);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        viewPager.setAdapter(new FragmentStateAdapter(this) {
            @NonNull
            @Override
            public Fragment createFragment(int position) {
                switch (position){
                    case 0:
                        return new AllPublishTaskFragment();
                    case 1:
                        return new AuditToBeFragment();
                    case 2:
                        return new AuditFinishedFragment();
                    default:
                        return new AuditUnqualifiedFragment();
                }
            }

            @Override
            public int getItemCount() {
                return 4;
            }
        });
        viewPager.setCurrentItem(1);
        new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
            switch (position) {
                case 0:
                    tab.setText("已发布");
                    break;
                case 1:
                    tab.setText("待审核");
                    break;
                case 2:
                    tab.setText("已完成");
                    break;
                default:
                    tab.setText("不合格");
            }
        }).attach();
    }
}